class smx_emqtt
{
  require smx_os
  Exec { path => [ '/bin/', '/sbin/' , '/usr/bin/', '/usr/sbin/' ] }

  file { '/opt/emqtt' :
      ensure  => directory,
      mode    => 777, owner => root, group => root,
      before => Exec["emqtt-download"]
    }

  case $get_server {
      'release-hf.sumilux.com','it-deploy.foxitcloud.com': {
        exec { "emqtt-download":
            command => "curl -O http://repo.connectedpdf.com:88/emqtt/emqttd-centos7-v2.0.7.zip",
            cwd => "/opt/emqtt",
        }
      }
      'ops30.sumilux.com': {
        exec { "emqtt-download":
            command => "curl -O http://emqtt.com/static/brokers/emqttd-centos7-v2.0.7.zip",
            cwd => "/opt/emqtt",
        }
      }
    }

  exec { 'unzipemqtt' :
        command => "unzip -qo /opt/emqtt/emqttd*.zip -d /opt/emqtt",
        cwd => "/opt/emqtt",
        require => Exec["emqtt-download"]
      }

  file { '/opt/emqtt/emqttd/etc/emq.conf':
    ensure => file,
    backup => false,
    owner =>root, group => root, mode => 644,
    source => 'puppet:///modules/smx_emqtt/emq.conf',
    require => Exec['unzipemqtt'],
  }

  file { '/etc/init.d/fxemqtt':
    ensure => file,
    owner  => root, group => root, mode => 755,
    source => 'puppet:///modules/smx_emqtt/fxemqtt',
  }

  service { 'fxemqtt':
    ensure    => running,
    enable    => true,
    path      => "/etc/init.d",
    start     => "/etc/init.d/fxemqtt start",
    stop      => "/etc/init.d/fxemqtt stop",
    subscribe => File["/etc/init.d/fxemqtt"],
    require   => File['/etc/init.d/fxemqtt'],
  }

}